<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Linux命令," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;ln 是 Linux 中又一个非常重要的命令，它的功能的功能是为某一个文件在另一个位置建立一个同步的连接。当需要在不同的目录，用到相同的文件时，就不需要在每个需要的目录下都放一个必须相同的文件，只要在某个固定的目录，放上该文件，然后在其他的目录下用 ln 命令连接（link）就可以，不必重复的占用磁盘空">
<meta name="keywords" content="Linux命令">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux 命令- ln">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/37. Linux 命令- ln/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;ln 是 Linux 中又一个非常重要的命令，它的功能的功能是为某一个文件在另一个位置建立一个同步的连接。当需要在不同的目录，用到相同的文件时，就不需要在每个需要的目录下都放一个必须相同的文件，只要在某个固定的目录，放上该文件，然后在其他的目录下用 ln 命令连接（link）就可以，不必重复的占用磁盘空">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-01T08:35:30.154Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux 命令- ln">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;ln 是 Linux 中又一个非常重要的命令，它的功能的功能是为某一个文件在另一个位置建立一个同步的连接。当需要在不同的目录，用到相同的文件时，就不需要在每个需要的目录下都放一个必须相同的文件，只要在某个固定的目录，放上该文件，然后在其他的目录下用 ln 命令连接（link）就可以，不必重复的占用磁盘空">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/37. Linux 命令- ln/"/>





  <title>Linux 命令- ln | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/37. Linux 命令- ln/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Linux 命令- ln</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T01:57:34+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ln 是 Linux 中又一个非常重要的命令，它的功能的功能是为某一个文件在另一个位置建立一个同步的连接。当需要在不同的目录，用到相同的文件时，就不需要在每个需要的目录下都放一个必须相同的文件，只要在某个固定的目录，放上该文件，然后在其他的目录下用 ln 命令连接（link）就可以，不必重复的占用磁盘空间。</p>
<h2 id="1-命令格式"><a href="#1-命令格式" class="headerlink" title="1.命令格式"></a>1.命令格式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ln [参数] [源文件或目录] [目标文件或目录]</div></pre></td></tr></table></figure>
<h2 id="2-命令功能"><a href="#2-命令功能" class="headerlink" title="2.命令功能"></a>2.命令功能</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Linux 文件系统中，有所谓的连接（link），可以将其视为档案的别名。而连接有可分为两种：硬链接（hard link）与软连接（symbolic link），硬连接的意思是一个档案可以有多个名称，而软连接的方式则是产生一个特殊的档案，该档案的内容是指向另一个档案的位置。硬链接是存在同一个文件系统中，而软连接却可以跨越不同的文件系统。</p>
<h3 id="软连接"><a href="#软连接" class="headerlink" title="软连接"></a>软连接</h3><ol>
<li><p>软连接，一路径的形式存在。类似与 windows 系统中的快捷方式；</p>
</li>
<li><p>软连接可以跨文件系统，硬链接不可以；</p>
</li>
<li><p>软连接可以对一个不存在的文件名进行连接；</p>
</li>
</ol>
<p>4.软连接可以对目录进行连接</p>
<h3 id="硬链接"><a href="#硬链接" class="headerlink" title="硬链接"></a>硬链接</h3><ol>
<li><p>硬链接，以文件副本的形式存在。但不占用实际空间；</p>
</li>
<li><p>不允许给目录创建硬链接；</p>
</li>
<li><p>硬链接只有在同一个文件系统中才能创建。</p>
</li>
</ol>
<h3 id="注意"><a href="#注意" class="headerlink" title="注意"></a>注意</h3><ol>
<li><p>ln 命令会保持每一处连接文件的同步性，也就是说，不论改动了哪一处，其他的文件都会发生相同的变化；</p>
</li>
<li><p>ln 的连接又分软连接和硬链接两种，软连接就是 <code>ln -s [源文件] [目标文件]</code> ，它只会在选定的位置上生成一个文件的镜像，不回占用磁盘空间，硬链接 <code>ln [源文件] [目标文件]</code> ，没有参数 -s ，会在选定的文职上生成一个和源文件大小相同的文件，无论是软连接还是硬链接，文件都保持同步变化。</p>
</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ln 指令在连接文件或目录，如同时指定两个以上的文件或目录，且最后的目的地是一个存在的目录，则会把前面指定的所有文件或目录复制到该目录中。若同时指定多个文件或目录，且最后的目的地并非是有一个已存在的目录，则会出现错误信息。</p>
<h2 id="3-命令参数"><a href="#3-命令参数" class="headerlink" title="3.命令参数"></a>3.命令参数</h2><h3 id="必要参数"><a href="#必要参数" class="headerlink" title="必要参数"></a>必要参数</h3><ul>
<li>-b 删除，覆盖以前建立的链接</li>
<li>-d 允许超级用户制作目录的硬链接</li>
<li>-f 强制执行</li>
<li>-i 交互模式，文件存在则提示用户是否覆盖</li>
<li>-n 把符号链接视为一般目录</li>
<li>-s 软链接(符号链接)</li>
<li>-v 显示详细的处理过程</li>
</ul>
<h3 id="选择参数"><a href="#选择参数" class="headerlink" title="选择参数"></a>选择参数</h3><ul>
<li>-S “-S&lt;字尾备份字符串&gt; ”或 “–suffix=&lt;字尾备份字符串&gt;”</li>
<li>-V “-V&lt;备份方式&gt;”或“–version-control=&lt;备份方式&gt;”</li>
<li>–help 显示帮助信息</li>
<li>–version 显示版本信息</li>
</ul>
<h2 id="使用实例"><a href="#使用实例" class="headerlink" title="使用实例"></a>使用实例</h2><h3 id="实例1：给文件创建软连接"><a href="#实例1：给文件创建软连接" class="headerlink" title="实例1：给文件创建软连接"></a>实例1：给文件创建软连接</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ln -s log2013.log link2013</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">-rw-r--r-- 1 root bin      61 11-13 06:03 log2013.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ln -s log2013.log link2013</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">lrwxrwxrwx 1 root root     11 12-07 16:01 link2013 -&gt; log2013.log</div><div class="line">-rw-r--r-- 1 root bin      61 11-13 06:03 log2013.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;为 log2013.log 文件创建软连接 link2013 ，如果 log2013.log 丢失，link2013 将失效。</p>
<h3 id="实例2：给文件创建硬连接"><a href="#实例2：给文件创建硬连接" class="headerlink" title="实例2：给文件创建硬连接"></a>实例2：给文件创建硬连接</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ln log2013.log ln2013</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">lrwxrwxrwx 1 root root     11 12-07 16:01 link2013 -&gt; log2013.log</div><div class="line">-rw-r--r-- 1 root bin      61 11-13 06:03 log2013.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ln log2013.log ln2013</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">lrwxrwxrwx 1 root root     11 12-07 16:01 link2013 -&gt; log2013.log</div><div class="line">-rw-r--r-- 2 root bin      61 11-13 06:03 ln2013</div><div class="line">-rw-r--r-- 2 root bin      61 11-13 06:03 log2013.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;为 log2013.log 创建硬链接 ln2013 ，log2013.log 与ln2013 的各项属性相同。</p>
<h3 id="实例3：接上面两实例，连接完毕后，删除和重建连接源文件"><a href="#实例3：接上面两实例，连接完毕后，删除和重建连接源文件" class="headerlink" title="实例3：接上面两实例，连接完毕后，删除和重建连接源文件"></a>实例3：接上面两实例，连接完毕后，删除和重建连接源文件</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">lrwxrwxrwx 1 root root     11 12-07 16:01 link2013 -&gt; log2013.log</div><div class="line">-rw-r--r-- 2 root bin      61 11-13 06:03 ln2013</div><div class="line">-rw-r--r-- 2 root bin      61 11-13 06:03 log2013.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># rm -rf log2013.log </span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">lrwxrwxrwx 1 root root     11 12-07 16:01 link2013 -&gt; log2013.log</div><div class="line">-rw-r--r-- 1 root bin      61 11-13 06:03 ln2013</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># touch log2013.log</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">lrwxrwxrwx 1 root root     11 12-07 16:01 link2013 -&gt; log2013.log</div><div class="line">-rw-r--r-- 1 root bin      61 11-13 06:03 ln2013</div><div class="line">---xrw-r-- 1 root bin  302108 11-13 06:03 log2012.log</div><div class="line">-rw-r--r-- 1 root root      0 12-07 16:19 log2013.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># vi log2013.log </span></div><div class="line">2013-01</div><div class="line">2013-02</div><div class="line">2013-03</div><div class="line">2013-04</div><div class="line">2013-05</div><div class="line">2013-06</div><div class="line">2013-07</div><div class="line">2013-08</div><div class="line">2013-09</div><div class="line">2013-10</div><div class="line">2013-11</div><div class="line">2013-12[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">lrwxrwxrwx 1 root root     11 12-07 16:01 link2013 -&gt; log2013.log</div><div class="line">-rw-r--r-- 1 root bin      61 11-13 06:03 ln2013</div><div class="line">-rw-r--r-- 1 root root     96 12-07 16:21 log2013.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat link2013 </span></div><div class="line">2013-01</div><div class="line">2013-02</div><div class="line">2013-03</div><div class="line">2013-04</div><div class="line">2013-05</div><div class="line">2013-06</div><div class="line">2013-07</div><div class="line">2013-08</div><div class="line">2013-09</div><div class="line">2013-10</div><div class="line">2013-11</div><div class="line">2013-12</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat ln2013 </span></div><div class="line">hostnamebaidu=baidu.com</div><div class="line">hostnamesina=sina.com</div><div class="line">hostnames=<span class="literal">true</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;1.源文件被删除后，并没有影响硬链接文件；软连接文件在 conetos 系统下不断的闪烁，提示远未见已经不存在</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;2.重建源文件后，团连接不再闪烁提示，说明已经连接成功，找到了连接文件系统；重建后，硬链接文件并没有收到源文件影响，硬链接文件的内容还是保留了删除前源文件的内容，说明硬链接已经失效。</p>
<h3 id="实例4：将文件链接为另一个目录中的相同名字"><a href="#实例4：将文件链接为另一个目录中的相同名字" class="headerlink" title="实例4：将文件链接为另一个目录中的相同名字"></a>实例4：将文件链接为另一个目录中的相同名字</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ln log2013.log test3</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ln log2013.log test3</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">lrwxrwxrwx 1 root root     11 12-07 16:01 link2013 -&gt; log2013.log</div><div class="line">-rw-r--r-- 1 root bin      61 11-13 06:03 ln2013</div><div class="line">-rw-r--r-- 2 root root     96 12-07 16:21 log2013.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test3</span></div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">-rw-r--r-- 2 root root 96 12-07 16:21 log2013.log</div><div class="line">[root@localhost test3]<span class="comment"># vi log2013.log </span></div><div class="line">2013-01</div><div class="line">2013-02</div><div class="line">2013-03</div><div class="line">2013-04</div><div class="line">2013-05</div><div class="line">2013-06</div><div class="line">2013-07</div><div class="line">2013-08</div><div class="line">2013-09</div><div class="line">2013-10[root@localhost test3]<span class="comment"># ll</span></div><div class="line">-rw-r--r-- 2 root root 80 12-07 16:36 log2013.log</div><div class="line">[root@localhost test3]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">lrwxrwxrwx 1 root root     11 12-07 16:01 link2013 -&gt; log2013.log</div><div class="line">-rw-r--r-- 1 root bin      61 11-13 06:03 ln2013</div><div class="line">-rw-r--r-- 2 root root     80 12-07 16:36 log2013.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 test3 目录中创建了 log2013.log 的硬链接，修改 test3 目录中的 log2013.log 文件，同时也会同步到源文件</p>
<h3 id="实例5：给目录创建软连接"><a href="#实例5：给目录创建软连接" class="headerlink" title="实例5：给目录创建软连接"></a>实例5：给目录创建软连接</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ln -sv /opt/soft/<span class="built_in">test</span>/test3 /opt/soft/<span class="built_in">test</span>/test5</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">drwxr-xr-x 2 root root   4096 12-07 16:36 test3</div><div class="line">drwxr-xr-x 2 root root   4096 12-07 16:57 test5</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test5</span></div><div class="line">[root@localhost test5]<span class="comment"># ll</span></div><div class="line">lrwxrwxrwx 1 root root 5 12-07 16:57 test3 -&gt; test3</div><div class="line">[root@localhost test5]<span class="comment"># cd test3</span></div><div class="line">-bash: <span class="built_in">cd</span>: test3: 符号连接的层数过多</div><div class="line">[root@localhost test5]<span class="comment"># </span></div><div class="line">[root@localhost test5]<span class="comment"># </span></div><div class="line">[root@localhost test5]<span class="comment"># ll</span></div><div class="line">lrwxrwxrwx 1 root root 5 12-07 16:57 test3 -&gt; test3</div><div class="line">[root@localhost test5]<span class="comment"># rm -rf test3</span></div><div class="line">[root@localhost test5]<span class="comment"># ll</span></div><div class="line">[root@localhost test5]<span class="comment"># ln -sv /opt/soft/test/test3 /opt/soft/test/test5</span></div><div class="line">创建指向“/opt/soft/<span class="built_in">test</span>/test3”的符号链接“/opt/soft/<span class="built_in">test</span>/test5/test3”</div><div class="line">[root@localhost test5]<span class="comment"># ll</span></div><div class="line">lrwxrwxrwx 1 root root 20 12-07 16:59 test3 -&gt; /opt/soft/<span class="built_in">test</span>/test3</div><div class="line">[root@localhost test5]<span class="comment"># </span></div><div class="line">[root@localhost test5]<span class="comment"># cd test3</span></div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">总计 4</div><div class="line">-rw-r--r-- 2 root root 80 12-07 16:36 log2013.log</div><div class="line">[root@localhost test3]<span class="comment"># touch log2014.log</span></div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">总计 4</div><div class="line">-rw-r--r-- 2 root root 80 12-07 16:36 log2013.log</div><div class="line">-rw-r--r-- 1 root root  0 12-07 17:05 log2014.log</div><div class="line">[root@localhost test3]<span class="comment"># cd ..</span></div><div class="line">[root@localhost test5]<span class="comment"># cd ..</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<ol>
<li><p>目录只能创建软连接      </p>
</li>
<li><p>目录创建链接必须用绝对路径，相对路径创建会不成功，会提示：符号连接的层数过多 ，这样的错误      </p>
</li>
<li><p>在连接目标目录中修改文件都会在源文件目录中同步变化</p>
</li>
</ol>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Linux命令/" rel="tag"># Linux命令</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/74. Linux 命令- rpm/" rel="next" title="Linux 命令- rpm">
                <i class="fa fa-chevron-left"></i> Linux 命令- rpm
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/35. Linux 命令- df/" rel="prev" title="Linux 命令- df">
                Linux 命令- df <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-命令格式"><span class="nav-number">1.</span> <span class="nav-text">1.命令格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-命令功能"><span class="nav-number">2.</span> <span class="nav-text">2.命令功能</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#软连接"><span class="nav-number">2.1.</span> <span class="nav-text">软连接</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#硬链接"><span class="nav-number">2.2.</span> <span class="nav-text">硬链接</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#注意"><span class="nav-number">2.3.</span> <span class="nav-text">注意</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-命令参数"><span class="nav-number">3.</span> <span class="nav-text">3.命令参数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#必要参数"><span class="nav-number">3.1.</span> <span class="nav-text">必要参数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#选择参数"><span class="nav-number">3.2.</span> <span class="nav-text">选择参数</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用实例"><span class="nav-number">4.</span> <span class="nav-text">使用实例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#实例1：给文件创建软连接"><span class="nav-number">4.1.</span> <span class="nav-text">实例1：给文件创建软连接</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例2：给文件创建硬连接"><span class="nav-number">4.2.</span> <span class="nav-text">实例2：给文件创建硬连接</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例3：接上面两实例，连接完毕后，删除和重建连接源文件"><span class="nav-number">4.3.</span> <span class="nav-text">实例3：接上面两实例，连接完毕后，删除和重建连接源文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例4：将文件链接为另一个目录中的相同名字"><span class="nav-number">4.4.</span> <span class="nav-text">实例4：将文件链接为另一个目录中的相同名字</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例5：给目录创建软连接"><span class="nav-number">4.5.</span> <span class="nav-text">实例5：给目录创建软连接</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
